﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;

public class Player : NetworkBehaviour {
    Vector2 pos;
    public ChessType chessColor;

    private void Start () {
        ChessBoard.Instance.AddPlayer (this);
    }

    private void Update () {
        if (!isLocalPlayer) {
            return;
        }
        PlayChess ();
    }

    private void OnApplicationQuit () {
        ChessBoard.Instance.DelPlayer (this);
    }

    public virtual void PlayChess () {
        if (Input.GetMouseButtonDown (0)) {
            pos = Camera.main.ScreenToWorldPoint (Input.mousePosition);
            ChessBoard.Instance.PlayChess (new int[2] {
                Round (pos.x) + 7, Round (pos.y) + 7
            });
        }
    }

    private int Round (float value) {
        if (value > 0)
            return (int) (value + 0.5F);
        else
            return (int) (value - 0.5F);
    }
}